package com.br.pfm.instituicao.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.logging.Logger;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.br.pfm.instituicao.bo.InstituicaoBO;
import com.br.pfm.persistence.model.Instituicao;

/**
 * Handles requests for the application home page.
 */
@Controller
@Slf4j
public class InstituicaoController {
	
	@Autowired
	InstituicaoBO instituicaoBO;
	
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home(Locale locale, Model model) {
		
		System.out.println("Welcome home! The client locale is {}.");
		
		List<Instituicao> instituicoesList = new ArrayList<Instituicao>();
		try {
			instituicoesList = instituicaoBO.getAllInstituicoes();
			System.out.println("### TAMANHO LISTA: ###" + instituicoesList.size());
		} catch (Exception e) {
			e.printStackTrace();
			Logger.getLogger("Erro no metodo do controller para listagem de instituicoes.");
			System.out.println("### TAMANHO LISTA: ###" + instituicoesList.size());
		}
		
		model.addAttribute("instituicoesList", instituicoesList);
		
		return "home";
	}
	
}

